<?php 
#!/usr/local/php/bin/php -q
/*
 * 短信脚本
*/

header('content-type:text/html;charset=utf-8');
define('DB_HOST','192.168.0.120');
define('DB_USER','kaka');
define('DB_PASS','kakameiye365');
define('DB_NAME','newmeiye');
define('DB_PORT',3306);
define('DB_CHAR','utf8');
define('APPNAME','');	

$conn=mysql_connect(DB_HOST.':'.DB_PORT,DB_USER,DB_PASS);
mysql_select_db(DB_NAME);
mysql_query('set names ' . DB_CHAR);

/*$sql = "ALTER TABLE `mfxhdatas` ADD COLUMN `number`  varchar(15)  NOT NULL COMMENT '企业编号' AFTER `yidayin`";
$result = mysql_query($sql);
$sql = "ALTER TABLE `mfxhdatas` ADD UNIQUE `number`(`number`)";
$result = mysql_query($sql);*/

$sql = "SELECT * FROM mfxhdatas ";
$result = mysql_query($sql);


$array=array();
while($rows=mysql_fetch_assoc($result)){
	if($rows['number']){
		continue;
	}
    $array[]=$rows;
}

foreach($array as $k=>$v){
		
	    $str = witch($v['ssqx'],$v['jjxz']);
	    $str .=code();
	    $sql = "UPDATE mfxhdatas SET `number`='$str' WHERE id=".$v['id'];
		$result = mysql_query($sql);
		//var_dump($str);
		$str='';
	
	
}

function witch($area,$n){
	$str = '';
	switch($area){
		case "东城区":
			$str.='101';break;
		case "西城区":
			$str.='102';break;
		case "朝阳区":
			$str.='103';break;
		case "丰台区":
			$str.='104';break;
		case "石景山区":
			$str.='105';break;
		case "海淀区":
			$str.='106';break;
		case "门头沟区":
			$str.='107';break;
		case "房山区":
			$str.='108';break;
		case "通州区":
			$str.='109';break;
		case "顺义区":
			$str.='110';break;
		case "昌平区":
			$str.='111';break;
		case "大兴区":
			$str.='112';break;
		case "怀柔区":
			$str.='113';break;
		case "平谷区":
			$str.='114';break;
		case "密云区":
			$str.='115';break;
		default:
			$str.='116';break;							
	}

	switch($n){
		case "个体工商户":
			$str.='201';break;
		case "国有独资":
			$str.='202';break;
		case "集体所有":
			$str.='203';break;
		case "有限责任公司":
			$str.='204';break;
		case "股份有限责任公司":
			$str.='205';break;
		case "外资企业":
			$str.='206';break;
		case "私营独资企业":
			$str.='207';break;
		default:
			$str.='208';break;						
	}

	return $str;

}


function code() {
    return  substr(implode(NULL, str_split(substr(uniqid(), 4,13), 1)), 0, 9);
}


